package cg.studio.algorithm.tree;

import java.util.LinkedList;
import java.util.Queue;

public abstract class TreeAbstractTraverse implements TreeTraverse
{
  public <T> void breadthTraverse( BinaryTree<T> root )
  {
    Queue<BinaryTree<T>> queue = new LinkedList<BinaryTree<T>>();
    queue.add( root );
    
    for(;;)
    {
      BinaryTree<T> tree = queue.poll();
      if( tree == null )
        break;
      
      tree.display();
      if( tree.getLeft() != null )
        queue.add( tree.getLeft() );
      if( tree.getRight() != null )
        queue.add( tree.getRight() );
    }
    
  }
}
